package cn.jxufe.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jxufe.bean.Message;
import cn.jxufe.entity.User;
import cn.jxufe.entity.SeedBag;
import cn.jxufe.service.SeedBagService;

/***
 * 种子收纳袋
 * @author Banner
 *
 */
@Controller@RequestMapping("seedBag")
public class SeedBagController {
	
	@Autowired private SeedBagService seedBagService;
	 /***
	  * 根据在线的用户信息获取该用户所有的种子收纳袋信息.
	  * @param session 请求
	  * @return 种子背包列表
	  */
	@RequestMapping("getList")
	@ResponseBody
	public List<SeedBag> getList(HttpSession session) { 
		System.out.println("getList成功！！！");
		List<SeedBag> userSeedLists = null;
		try {
			User curUser = (User) session.getAttribute("curUser");
			int userId = (int)curUser.getId();
			
			userSeedLists = seedBagService.getList(userId); 
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("您还未登录！！！");
		}
		return userSeedLists;
	}
	
	/***
	 * 用于页面布局修改.
	 * @param session 请求
	 * @param model model
	 */
	@RequestMapping("doNotSee")
	@ResponseBody
	public void doNot(HttpSession session, Model model) {
		session.setAttribute("tools", "false");
	}
	
	/***
	 * 购买种子.
	 * @param session 请求
	 * @param seedBag 种子收纳袋实体
	 * @param model model
	 * @return Message
	 */
	@RequestMapping("buySeed")
	@ResponseBody
	public Message buySeed(HttpSession session, @RequestBody SeedBag seedBag, Model model) {
		return seedBagService.buySeed(session, seedBag);
	}
}
